﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FurnitureSystem
{
    public partial class frmQuanLyKH : Form
    {
        SqlConnection conn;
        SqlCommand cmd;
        SqlDataAdapter da;
        public static string MaKH;
        public frmQuanLyKH()
        {
            InitializeComponent();
        }

        private void dgDSKH_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void frmQuanLyKH_Load(object sender, EventArgs e)
        {
            conn = connect.Getconect();
            conn.Open();
            string sql = "select Customerid[Mã khách hàng],Cust_name[Tên khách hàng],Contactno[Số điện thoại],Addr[Địa chỉ],Orderid[Mã hoá đơn] from Customer";
            cmd = new SqlCommand(sql, conn);
            da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds, "cus");
            dgDSKH.DataSource = ds.Tables[0];
            conn.Close();
        }



        private void btnTimten_Click(object sender, EventArgs e)
        {
            conn = connect.Getconect();
            conn.Open();
            string sql = "select Customerid[Mã khách hàng],Cust_name[Tên khách hàng],Contactno[Số điện thoại],Addr[Địa chỉ],Orderid[Mã hoá đơn] from Customer where Cust_name like '%" + txtTenKH.Text + "%'";
            cmd = new SqlCommand(sql, conn);
            da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds, "cus");
            dgDSKH.DataSource = ds.Tables[0];
            conn.Close();
        }

        private void btnXemthongtin_Click(object sender, EventArgs e)
        {
            MaKH = dgDSKH.CurrentRow.Cells[4].Value.ToString();
            frmThongtinmuahang frmThongtinmuahang = new frmThongtinmuahang();
            frmThongtinmuahang.Show();
            

        }

        private void btnThemKH_Click(object sender, EventArgs e)
        {
            frmThemKH frmThemKH = new frmThemKH();
            frmThemKH.Show();
        }

        private void btnTrove_Click(object sender, EventArgs e)
        {
            frmMain frmMain = new frmMain();
            frmMain.Show();
            this.Hide();
        }



    }
}
